package com.mashibing.serviceverificationcode.controller;

import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.response.NumberCodeResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ServiceVerificationCodeController {

    @GetMapping("/numberCode/{size}")
    public ResponseResult numberCode(@PathVariable int size) {

        // 生成验证码
        int random = (int) ((Math.random() * 9 + 1) * Math.pow(10, size - 1));
        System.out.println("验证码为" + random);
        NumberCodeResponse numberCodeResponse = new NumberCodeResponse();
        numberCodeResponse.setNumberCode(random);

        // 返回
        return ResponseResult.success(numberCodeResponse);
    }
}
